﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for NhaSanXuatDAO
/// </summary>
public class NhaSanXuatDAO : AbstractDAO
{
    public NhaSanXuatDAO(String strPath)
        : base(strPath)
    {

    }
    ~NhaSanXuatDAO()
    {
        base.Dispose();
    }

    public DataSet SelectNhaSanXuatAll()
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectNhaSanXuatAll";
            base.FillDataSet(ref ds, "SelectNhaSanXuatAll");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectNhaSanXuatLoaiSanPham()
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectNhaSanXuatLoaiSanPham";

            base.FillDataSet(ref ds, "SelectNhaSanXuatLoaiSanPham");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectNhaSanXuatByLoaiSanPham(int id)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectNhaSanXuatByLoaiSanPham";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            base.FillDataSet(ref ds, "SelectNhaSanXuatByLoaiSanPham");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectNhaSanXuat_AutoComplete(string input)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectNhaSanXuat_AutoComplete";
            base.InitializeCommand();

            base.AddParameter("@input",
            SqlDbType.NVarChar, 100, input);

            base.FillDataSet(ref ds, "SelectNhaSanXuat_AutoComplete");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectTenNSX(int id)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectTenNSX";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            base.FillDataSet(ref ds, "SelectTenNSX");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public Boolean InsertNhaSanXuat(NhaSanXuatDTO nsx)
    {
        try
        {
            base.sql = "usp_InsertNhaSanXuat";
            base.InitializeCommand();

            base.AddParameter("@TenNSX",
            SqlDbType.NVarChar, 100, nsx.TenNSX);

            base.AddParameter("@QuocGia",
            SqlDbType.NVarChar, 100, nsx.QuocGia);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            return false;

        }
    }

    public Boolean InsertNhaSanXuat_LoaiSP(string nsx, int loaisp)
    {
        try
        {
            base.sql = "usp_InsertNhaSanXuat_LoaiSP";
            base.InitializeCommand();

            base.AddParameter("@TenNSX",
            SqlDbType.NVarChar, 100, nsx);

            base.AddParameter("@idLoaiSP",
            SqlDbType.Int, 10, loaisp);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            return false;

        }
    }

    public Boolean UpdateNhaSanXuat(NhaSanXuatDTO nsx)
    {
        try
        {
            base.sql = "usp_UpdateNhaSanXuat";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, nsx.Id);

            base.AddParameter("@TenNSX",
            SqlDbType.NVarChar, 100, nsx.TenNSX);

            base.AddParameter("@QuocGia",
            SqlDbType.NVarChar, 100, nsx.QuocGia);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            return false;

        }
    }

    public Boolean DeleteNhaSanXuat(int id)
    {
        try
        {
            base.sql = "usp_DeleteNhaSanXuat";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);
        }
    }

}